package com.sfddata.musicpillow.common.utils;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

public class uploadFile {

    public static void main(String[] args) {

        String filePath = "/Users/jiangyingou/Documents/video";
        File dir = new File(filePath);

        ArrayList<File> allFileList = new ArrayList<>();

        if(!dir.exists()){

            System.out.println("目录不存在");
            return;
        }

        getAllFile(dir, allFileList);

        for (File file : allFileList) {
            System.out.println(file.getAbsolutePath());
        }


        System.out.println("该文件夹下共有" + allFileList.size() + "个文件");
    }

    public static void getAllFile(File fileInput,
                                   List<File> allFileList){
        File[] fileList = fileInput.listFiles();
        assert fileList != null;
        for (File file : fileList) {
            if (file.isDirectory()) {
                // 递归处理文件夹
                // 如果不想统计子文件夹则可以将下一行注释掉
                getAllFile(file, allFileList);
            } else {
                // 如果是文件则将其加入到文件数组中
                allFileList.add(file);
            }
        }
    }


}
